home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12182 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.0 KB  |  70 lines

  1. Path: lrz-muenchen.de!news
  2. From: watzka@stat.uni-muenchen.de (Kurt Watzka)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Int to Double, Pl Advise!
  5. Date: 29 Mar 1996 18:03:01 GMT
  6. Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
  7. Distribution: world
  8. Message-ID: <4jh8kl$g5v@sparcserver.lrz-muenchen.de>
  9. References: <isa5224.544.315B647A@age2.age.uiuc.edu>
  10. NNTP-Posting-Host: sun2.lrz-muenchen.de
  11.  
  12. isa5224@age2.age.uiuc.edu (Irfan S. Ahmad) writes:
  13.  
  14. >Hi:
  15.  
  16. >I am having problems with the following type conversion.  From int to double.  
  17. >If someone can comment:
  18.  
  19. >#define Ng 4
  20. >#define Nr 4
  21.  
  22. >#include <stdio.h>
  23. >#include <math.h>
  24. >#include <malloc.h> 
  25.  
  26. May including  this header changes the meaning of all statements
  27. that follow. I will assume that this is not the case, i.e. that
  28. this header was _not_ included.
  29.  
  30. >int p0[Ng][Nr];
  31.  
  32. >int main(){
  33. >int i,j,k;  
  34. >float x =0;
  35. >float y =0; 
  36. >:
  37. >for (i=1; i<Ng; i++) { 
  38. >    for (j=1; j<Nr; j++) {
  39. >   
  40. >     x = x + ((double) p0[i,j]) / (double)(j*j); }
  41.  
  42. "p0[i,j]" is equivalent to "p0[j]", the only difference is that
  43. "i" is evaluated, too. If the evaluation of "i" has any side
  44. effects (which I doubt in your example), the statements are
  45. different, otherwise the are equivalent.
  46.  
  47. "p[j]" is an "array of Nr doubles". Unfortunately,  C does not
  48. do the obvious thing in this situation, i.e. divide all elements
  49. of the array by the second operand of "/". Some matrix or vector
  50. oriented languages are defined that way, but C is not such a 
  51. language.
  52.  
  53. >}
  54.  
  55. >I get the following compilation error(s) on MS C++ compiler:
  56. >error C2440: 'cast' : cannot convert from 'int [4]' to 'double '
  57.  
  58. >Please post or preferably email your comments to:
  59.  
  60. If you want to contribute something to reducing the noise level
  61. in this group, post your question, ask for email replies, _and_
  62. offer to post a summary of the answers you got. If you want
  63. private tutition, pay for it.
  64.  
  65. Kurt
  66. --
  67. | Kurt Watzka                             Phone : +49-89-2180-6254
  68. | watzka@stat.uni-muenchen.de
  69.